export default {
	getUrl() {
		try {
			const value = uni.getStorageSync('serverurl')
			if (value && value !== '') {
				return value
			} else {
				uni.showToast({
					title: "请先配置API",
					duration: 2000,
					icon: "error"
				})
			}
		} catch (e) {
			uni.showToast({
				title: "请先配置API",
				duration: 2000,
				icon: "error"
			})
		}
	},
	async dkRequest(data){
		let res = {}
		try{
			res = await uni.request(data)
		}catch(e){
			console.log(e);
			res.data = {code: 5000,message:'请求失败'}
		}
		return res
	},
	async uploadFile(data){
		let res = {}
		try{
			res = await uni.uploadFile(data);
		}catch(e){
			console.log(e);
			res.data = {code: 5000,message:'请求失败'}
		}
		return res
	},
	async UpMusicByUrl(that, music) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/MusicApi/UpMusicByUrl";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: music
		})
		console.log(res.data)
		return res.data
	},
	async CreateMusicGroup(that, musicGroup) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/MusicApi/CreateMusicGroup";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: musicGroup
		})
		console.log(res.data)
		return res.data
	},
	async updateMusicGroupMusic(that, musicGroup) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/MusicApi/updateMusicGroupMusic";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: musicGroup
		})
		console.log(res.data)
		return res.data
	},
	async GetMusicGroupList(that) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/MusicApi/GetMusicGroupList";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: {}
		})
		console.log(res.data)
		return res.data
	},
	async GetMusicGroup(that, musicGroup) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/MusicApi/GetMusicGroup";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: musicGroup
		})
		console.log(res.data)
		return res.data
	},
	async GetMusicList(that) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/MusicApi/GetMusicList";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: {}
		})
		console.log(res.data)
		return res.data
	},
	async NextMusic(that) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/MusicApi/NextMusic";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: {}
		})
		console.log(res.data)
		return res.data
	},
	async SelectMusic(that, music) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/MusicApi/SelectMusic";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: music
		})
		console.log(res.data)
		return res.data
	},
	async SetMusic(that, music) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/MusicApi/SetMusic";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: music
		})
		console.log(res.data)
		return res.data
	},
	async DeleteMusicGroup(that, musicGroup) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/MusicApi/DeleteMusicGroup";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: musicGroup
		})
		console.log(res.data)
		return res.data
	},
	async UpMusicImg(that, tempFilePath, music) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/MusicApi/UpMusicImg";
		console.log(url)
		const res = await that.HttpTool.uploadFile({
			url: url, //仅为示例，非真实的接口地址
			filePath: tempFilePath,
			name: 'file',
			formData: music
		});
		console.log(res.data)
		return res.data
	},
	async UpMusic(that, tempFilePath, music) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/MusicApi/UpMusic";
		console.log(url)
		const res = await that.HttpTool.uploadFile({
			url: url, //仅为示例，非真实的接口地址
			filePath: tempFilePath,
			name: 'file',
			formData: music,
			timeout:300000
		});
		console.log(res.data)
		return res.data
	},
	async UserLo(that, user) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/UserApi/UserLo";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: user
		})
		console.log(res.data)
		return res.data
	},
	async UpdateUser(that, user) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/UserApi/UpdateUser";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: user
		})
		console.log(res.data)
		return res.data
	},
	async UpUserImg(that, tempFilePath) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/UserApi/UpUserImg";
		console.log(url)
		const res = await that.HttpTool.uploadFile({
			url: url, //仅为示例，非真实的接口地址
			filePath: tempFilePath,
			name: 'file',
			formData: {},
			timeout:300000
		});
		console.log(res.data)
		return res.data
	},
	async GetMsg(that,time) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/ImApi/GetMsg";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: {
				'time':time
			}
		})
		console.log(res.data)
		return res.data
	},
	async SendMsg(that,imMsg) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/ImApi/SendMsg";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: imMsg
		})
		console.log(res.data)
		return res.data
	},
	async UpImFile(that, tempFilePath) {
		console.log(tempFilePath)
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/ImApi/UpImFile";
		console.log(url)
		const res = await that.HttpTool.uploadFile({
			url: url, //仅为示例，非真实的接口地址
			filePath: tempFilePath,
			name: 'file',
			formData: {},
			timeout:300000
		});
		console.log(res.data)
		return res.data
	},
	async GetMsgHistory(that,time) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/ImApi/GetMsgHistory";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: {
				'time':time
			}
		})
		console.log(res.data)
		return res.data
	},
	async SetPsw(that, user) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/UserApi/SetPsw";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: user
		})
		console.log(res.data)
		return res.data
	},
	async SetOtherDevice(that, user) {
		var url = that.HttpTool.getUrl()
		if (!url || url === '') {
			return
		}
		url = url + "/UserApi/SetOtherDevice";
		console.log(url)
		const res = await that.HttpTool.dkRequest({
			url: url,
			method: 'POST',
			data: user
		})
		console.log(res.data)
		return res.data
	},
}
